home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Files / Directories / CatInfo.h < prev    next >
Text File  |  2000-06-23  |  9KB  |  217 lines

  1. // CatInfo.h
  2.  
  3. #ifndef CatInfo_h
  4. #define CatInfo_h
  5.  
  6. #ifndef FileLocation_h
  7. #include "FileLocation.h"
  8. #endif
  9. #ifndef __FINDER__
  10. #include <Finder.h>
  11. #endif
  12. #ifndef AllocationBlock_h
  13. #include "AllocationBlock.h"
  14. #endif
  15.  
  16. class CatInfo: public CInfoPBRec
  17.   {
  18.     private:
  19.         FileLocation location;
  20.         
  21.         void ThrowError( OSErr );
  22.         
  23.         bool Attribute( uint8 bit ) const                                { return ( hFileInfo.ioFlAttrib & bit ) != 0; }
  24.         bool Flag( uint16 bit ) const                                        { return ( hFileInfo.ioFlFndrInfo.fdFlags & bit ) != 0; }
  25.         void SetFlag( uint16 bit )                                            { hFileInfo.ioFlFndrInfo.fdFlags |= bit; }
  26.         void ClearFlag( uint16 bit )                                        { hFileInfo.ioFlFndrInfo.fdFlags &= uint16(~bit); }
  27.  
  28.     public:
  29.         CatInfo();
  30.         CatInfo( const FileLocation& );
  31.         CatInfo( ::Directory );
  32.         CatInfo( ::Directory, ConstPString );
  33.         CatInfo( ::Directory, int16 index );
  34.         CatInfo( const CInfoPBRec& );
  35.         
  36.         CatInfo( const CatInfo& );
  37.         void operator=( const CatInfo& );
  38.         
  39.         void Get();
  40.         void Get( const FileLocation& );
  41.         void Get( ::Directory );
  42.         void Get( ::Directory, ConstPString );
  43.         void Get( ::Directory, int16 index );
  44.         
  45.         // These return false on nonexistence:
  46.             bool TryToGet( ::Directory, int16 index );
  47.             bool TryToGet( const FileLocation& );
  48.             bool TryToGet();
  49.          
  50.         void Set();
  51.         void Set( const FileLocation& );
  52.         
  53.         bool IsRoot() const                                                    { return location.IsRoot(); }
  54.         
  55.         void Up();
  56.         void Down( ConstPString );
  57.         void Sideways( ConstPString );
  58.         
  59.         const FileLocation& Location() const                            { return location; }
  60.         ::Directory AsDirectory() const;
  61.         
  62.         bool Locked() const                                                    { return Attribute( 0x01 ); }
  63.         bool IsDirectory() const                                            { return Attribute( 0x10 ); }
  64.         bool IsFile() const                                                    { return !Attribute( 0x10 ); }
  65.         
  66.         bool Invisible() const                                                { return Flag( fInvisible ); }
  67.         bool NameLocked() const                                                { return Flag( kNameLocked ); }
  68.         bool HasCustomIcon() const                                            { return Flag( kHasCustomIcon ); }
  69.         bool SeenByFinder() const                                            { return Flag( kHasBeenInited ); }
  70.  
  71.         void BeInvisible()                                                    { SetFlag( fInvisible ); }
  72.         void LockName()                                                        { SetFlag( kNameLocked ); }
  73.         void HaveCustomIcon()                                                { SetFlag( kHasCustomIcon ); }
  74.         void BeSeenByFinder()                                                { SetFlag( kHasBeenInited ); }
  75.  
  76.         void BeVisible()                                                        { ClearFlag( fInvisible ); }
  77.         void UnlockName()                                                        { ClearFlag( kNameLocked ); }
  78.         void HaveNoCustomIcon()                                                { ClearFlag( kHasCustomIcon ); }
  79.         void BeUnseenByFinder()                                                { ClearFlag( kHasBeenInited ); }
  80.  
  81.         uint8 Label() const                                                    { return uint8( ( hFileInfo.ioFlFndrInfo.fdFlags & kColor ) >> 1 ); }
  82.         void SetLabel( uint8 );
  83.         
  84.         Point LocationInWindow() const                                    { return hFileInfo.ioFlFndrInfo.fdLocation; }
  85.         void SetLocationInWindow( Point p )                                { hFileInfo.ioFlFndrInfo.fdLocation = p; }
  86.  
  87.         uint32 CreationTime() const                                        { return hFileInfo.ioFlCrDat; }
  88.         uint32 ModificationTime() const                                    { return hFileInfo.ioFlMdDat; }
  89.         uint32 BackupTime() const                                            { return hFileInfo.ioFlBkDat; }
  90.  
  91.         void SetCreationTime( uint32 t )                                    { hFileInfo.ioFlCrDat = t; }
  92.         void SetModificationTime( uint32 t )                            { hFileInfo.ioFlMdDat = t; }
  93.         void SetBackupTime( uint32 t )                                    { hFileInfo.ioFlBkDat = t; }
  94.         
  95.         bool HasScript() const                                                { return (hFileInfo.ioFlXFndrInfo.fdScript & 0x80) != 0; }
  96.         ScriptID Script() const                                                { return ScriptID( int16( hFileInfo.ioFlXFndrInfo.fdScript & 0x7f ) ); }
  97.         
  98.         void HaveNoScript()                                                    { hFileInfo.ioFlXFndrInfo.fdScript = 0; }
  99.         void HaveScript( ScriptID s )                                        { hFileInfo.ioFlXFndrInfo.fdScript = int8(s.ID() | 0x80); }
  100.  
  101.         DirectoryID PutAwayPlace() const                                    { return DirectoryID( hFileInfo.ioFlXFndrInfo.fdPutAway ); }
  102.         void SetPutAwayPlace( DirectoryID id )                            { hFileInfo.ioFlXFndrInfo.fdPutAway = id.Number(); }
  103.         
  104.         
  105.         class DirectoryCatInfo: public DirInfo
  106.           {
  107.             private:
  108.                 bool Attribute( uint8 bit ) const                                { return ( ioFlAttrib & bit ) != 0; }
  109.                 bool Access( uint8 bit ) const                                    { return ( ioACUser & bit ) != 0; }
  110.                 
  111.             public:
  112.                 bool Shared() const                                                    { return Attribute( 0x04 ); }
  113.                 bool IsMountedSharePoint() const                                    { return Attribute( 0x08 ); }
  114.                 bool IsSharePoint() const                                            { return Attribute( 0x20 ); }
  115.  
  116.                 bool CantSeeFolders() const                                        { return Access( 0x01 ); }
  117.                 bool CantSeeFiles() const                                            { return Access( 0x02 ); }
  118.                 bool CantMakeChanges() const                                        { return Access( 0x04 ); }
  119.                 bool NotOwner() const                                                { return Access( 0x80 ); }
  120.                 
  121.                 DirectoryID ID() const                                                { return DirectoryID( ioDrDirID ); }
  122.                 uint16 FileCount() const                                            { return ioDrNmFls; }
  123.           };
  124.         
  125.         
  126.         class FileCatInfo: public HFileInfo
  127.           {
  128.             private:
  129.                 bool Attribute( uint8 bit ) const                                { return ( ioFlAttrib & bit ) != 0; }
  130.                 bool Flag( uint16 bit ) const                                        { return ( ioFlFndrInfo.fdFlags & bit ) != 0; }
  131.                 void SetFlag( uint16 bit )                                            { ioFlFndrInfo.fdFlags |= bit; }
  132.                 void ClearFlag( uint16 bit )                                        { ioFlFndrInfo.fdFlags &= uint16(~bit); }
  133.  
  134.             public:
  135.                 int16 ReferenceNumber() const                                        { return ioFRefNum; }
  136.                 
  137.                 bool IsOpen() const                                                    { return Attribute( 0x80 ); }
  138.                 bool CopyProtected() const                                            { return Attribute( 0x40 ); }
  139.                 
  140.                 FileType Type() const                                                { return FileType( ioFlFndrInfo.fdType ); }
  141.                 FileSignature Signature() const                                    { return FileSignature( ioFlFndrInfo.fdCreator ); }
  142.                 
  143.                 void SetType( FileType t )                                            { ioFlFndrInfo.fdType = t.Type(); }
  144.                 void SetSignature( FileSignature s )                            { ioFlFndrInfo.fdCreator = s.Signature(); }
  145.                 
  146.                 bool IsAlias() const                                                    { return Flag( kIsAlias ); }
  147.                 bool HasBundle() const                                                { return Flag( fHasBundle ); }
  148.                 bool IsStationery() const                                            { return Flag( kIsStationery ); }
  149.                 bool HasNoInits() const                                                { return Flag( 0x80 ); }
  150.                 bool IsSharableApplication() const                                { return Flag( kIsShared ); }
  151.  
  152.                 void BeAlias()                                                            { SetFlag( kIsAlias ); }
  153.                 void HaveBundle()                                                        { SetFlag( fHasBundle ); }
  154.                 void BeStationery()                                                    { SetFlag( kIsStationery ); }
  155.                 void HaveNoInits()                                                    { SetFlag( 0x80 ); }
  156.                 void BeSharableApplication()                                        { SetFlag( kIsShared ); }
  157.  
  158.                 void BeNotAlias()                                                        { ClearFlag( kIsAlias ); }
  159.                 void HaveNoBundle()                                                    { ClearFlag( fHasBundle ); }
  160.                 void BeNotStationery()                                                { ClearFlag( kIsStationery ); }
  161.                 void HaveInits()                                                        { ClearFlag( 0x80 ); }
  162.                 void BeNotSharableApplication()                                    { ClearFlag( kIsShared ); }
  163.                 
  164.                 FileID ID() const                                                        { return FileID( ioDirID ); }
  165.  
  166.                 uint32 ClumpSize() const                                            { return uint32(ioFlClpSiz); }
  167.                 
  168.                 
  169.                 class DataForkInfo: public HFileInfo
  170.                   {
  171.                     private:
  172.                         bool Attribute( uint8 bit ) const                                { return ( ioFlAttrib & bit ) != 0; }
  173.                     
  174.                     public:
  175.                         uint32 LogicalLength() const                                        { return uint32(ioFlLgLen); }
  176.                         uint32 PhysicalLength() const                                        { return uint32(ioFlPyLen); }
  177.                         AllocationBlock FirstAllocationBlock() const                    { return AllocationBlock( ioFlStBlk ); }
  178.  
  179.                         bool IsOpen() const                                                    { return Attribute( 0x08 ); }
  180.                         
  181.                         bool Exists() const                                                    { return ioFlStBlk != 0; }
  182.                   };
  183.                 
  184.                 
  185.                 class ResourceForkInfo: public HFileInfo
  186.                   {
  187.                     private:
  188.                         bool Attribute( uint8 bit ) const                                { return ( ioFlAttrib & bit ) != 0; }
  189.                     
  190.                     public:
  191.                         uint32 LogicalLength() const                                        { return uint32(ioFlRLgLen); }
  192.                         uint32 PhysicalLength() const                                        { return uint32(ioFlRPyLen); }
  193.                         AllocationBlock FirstAllocationBlock() const                    { return AllocationBlock( ioFlRStBlk ); }
  194.  
  195.                         bool IsOpen() const                                                    { return Attribute( 0x04 ); }
  196.                         
  197.                         bool Exists() const                                                    { return ioFlRStBlk != 0; }
  198.                   };
  199.                 
  200.                 
  201.                 DataForkInfo& Data()                                    { return static_cast< DataForkInfo& >( static_cast< HFileInfo &>( *this ) ); }
  202.                 const DataForkInfo& Data() const                    { return static_cast< const DataForkInfo& >( static_cast< const HFileInfo& >( *this ) ); }
  203.  
  204.                 ResourceForkInfo& Resources()                        { return static_cast< ResourceForkInfo& >( static_cast< HFileInfo& >( *this ) ); }
  205.                 const ResourceForkInfo& Resources() const        { return static_cast< const ResourceForkInfo& >( static_cast< const HFileInfo& >( *this ) ); }
  206.           };
  207.         
  208.         
  209.         DirectoryCatInfo& Directory()                                { Assert( IsDirectory() );    return static_cast< DirectoryCatInfo& >( dirInfo ); }
  210.         const DirectoryCatInfo& Directory() const                { Assert( IsDirectory() ); return static_cast< const DirectoryCatInfo& >( dirInfo ); }
  211.         
  212.         FileCatInfo& File()                                            { Assert( !IsDirectory() ); return static_cast< FileCatInfo& >( hFileInfo ); }
  213.         const FileCatInfo& File() const                            { Assert( !IsDirectory() ); return static_cast< const FileCatInfo& >( hFileInfo ); }
  214.   };
  215.  
  216. #endif
  217.